﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for TAMoreDetailChinaTaipingDB
/// </summary>
public class TAMoreDetailChinaTaipingDB
{
	public TAMoreDetailChinaTaipingDB()
	{
		//
		// TODO: Add constructor logic here
		//
	}


    public Int64 Insert(TAMoreDetailChinaTaiping TAMoreDetailChinaTaiping)
    {
        MyDatabase _db = new MyDatabase();
        Int64 _result = -1;
        string _spName = "[sprocTAMoreDetailInsertUpdateSingleItemChinaTaiping]";

        SortedList _sPara = new SortedList();

        #region Parameter
        _sPara.Add("@CETAMoreDetailId", TAMoreDetailChinaTaiping.cetaMoreDetailId);
        _sPara.Add("@CETAInsId", TAMoreDetailChinaTaiping.cetaInsId);
        _sPara.Add("@CETAID", TAMoreDetailChinaTaiping.cetaId);
        _sPara.Add("@ProviderCompanyId", TAMoreDetailChinaTaiping.ProviderCompanyId);
        _sPara.Add("@Name", TAMoreDetailChinaTaiping.Name);
        _sPara.Add("@PostalCode", TAMoreDetailChinaTaiping.PostalCode);
        _sPara.Add("@UnitNo", TAMoreDetailChinaTaiping.UnitNo);
        _sPara.Add("@HomeNo", TAMoreDetailChinaTaiping.HomeNo);
        _sPara.Add("@Address", TAMoreDetailChinaTaiping.Address);
        _sPara.Add("@NRICNo", TAMoreDetailChinaTaiping.NRICNo);
        _sPara.Add("@Nationality", TAMoreDetailChinaTaiping.Nationality);
        _sPara.Add("@MobileNo", TAMoreDetailChinaTaiping.MobileNo);
        _sPara.Add("@HomePhoneNo", TAMoreDetailChinaTaiping.HomePhoneNo);
        _sPara.Add("@OfficePhoneNo", TAMoreDetailChinaTaiping.OfficePhoneNo);
        _sPara.Add("@FaxNo", TAMoreDetailChinaTaiping.FaxNo);
        _sPara.Add("@Email", TAMoreDetailChinaTaiping.Email);
        _sPara.Add("@EmpName", TAMoreDetailChinaTaiping.EmpName);
        _sPara.Add("@PlanName", TAMoreDetailChinaTaiping.PlanName);
        _sPara.Add("@PlanType", TAMoreDetailChinaTaiping.PlanType);
        _sPara.Add("@TripType", TAMoreDetailChinaTaiping.TripType);
        _sPara.Add("@CoverageLevel", TAMoreDetailChinaTaiping.CoverageLevel);
        _sPara.Add("@Country", TAMoreDetailChinaTaiping.Country);
        _sPara.Add("@Area", TAMoreDetailChinaTaiping.Area);
        _sPara.Add("@Duration", TAMoreDetailChinaTaiping.Duration);
        _sPara.Add("@StartDate", TAMoreDetailChinaTaiping.StartDate);
        _sPara.Add("@EndDate", TAMoreDetailChinaTaiping.EndDate);
        _sPara.Add("@ChildAge", TAMoreDetailChinaTaiping.ChildAge);
        _sPara.Add("@AdultAge", TAMoreDetailChinaTaiping.AdultAge);
        _sPara.Add("@NoOfTraveller", TAMoreDetailChinaTaiping.NoOfTraveller);
        _sPara.Add("@TotalPremium", TAMoreDetailChinaTaiping.TotalPremium);
        _sPara.Add("@PamentType", TAMoreDetailChinaTaiping.PamentType);
        _sPara.Add("@RefCEUserId", TAMoreDetailChinaTaiping.RefCEUserId);
        _sPara.Add("@ViewedDetailId", TAMoreDetailChinaTaiping.ViewedDetailId);
        _sPara.Add("@Status", TAMoreDetailChinaTaiping.Status);
        _sPara.Add("@Info1", TAMoreDetailChinaTaiping.Info1);
        _sPara.Add("@Info2", TAMoreDetailChinaTaiping.Info2);
        #endregion

        _result = _db.ExecuteSP(_spName, _sPara);

        return _result;
    }

    public bool Update()
    {
        return true;
    }

    public bool Delete()
    {
        return true;
    }

    public TAMoreDetailChinaTaiping GetTAMoreDetail(Int64 TAId, Int64 CEUserId)
    {
        TAMoreDetailChinaTaiping _tamoredetail = null;
        MyDatabase _db = new MyDatabase();
        string _spName = "sprocTAMoreDetailSelectSingleItemChinaTaiping";

        SortedList _spara = new SortedList();
        _spara.Add("@CETAid", TAId);
        _spara.Add("@RefCEUserId", CEUserId);

        DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
        if (_dt != null)
        {
            if (_dt.Rows.Count > 0)
            {
                _tamoredetail = new TAMoreDetailChinaTaiping();
                _tamoredetail = FillDataRecord(_dt);
            }
        }
        return _tamoredetail;
    }

    private TAMoreDetailChinaTaiping FillDataRecord(DataTable myDataTable)
    {
        TAMoreDetailChinaTaiping myTAMoreDetail = new TAMoreDetailChinaTaiping();
        myTAMoreDetail.cetaMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["cetaMoreDetailId"].ToString());
        myTAMoreDetail.cetaInsId = Convert.ToInt64(myDataTable.Rows[0]["cetaInsId"].ToString());
        myTAMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
        myTAMoreDetail.cetaId = Convert.ToInt64(myDataTable.Rows[0]["cetaId"].ToString());
        myTAMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
        myTAMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
        myTAMoreDetail.UnitNo = myDataTable.Rows[0]["UnitNo"].ToString();
        myTAMoreDetail.HomeNo = myDataTable.Rows[0]["HomeNo"].ToString();
        myTAMoreDetail.Address = myDataTable.Rows[0]["Address"].ToString();
        myTAMoreDetail.NRICNo = myDataTable.Rows[0]["NRICNo"].ToString();
        myTAMoreDetail.Nationality = myDataTable.Rows[0]["Nationality"].ToString();
        myTAMoreDetail.MobileNo = myDataTable.Rows[0]["MobileNo"].ToString();
        myTAMoreDetail.HomePhoneNo = myDataTable.Rows[0]["HomePhoneNo"].ToString();
        myTAMoreDetail.OfficePhoneNo = myDataTable.Rows[0]["OfficePhoneNo"].ToString();
        myTAMoreDetail.FaxNo = myDataTable.Rows[0]["FaxNo"].ToString();
        myTAMoreDetail.Email = myDataTable.Rows[0]["Email"].ToString();
        myTAMoreDetail.EmpName = myDataTable.Rows[0]["EmpName"].ToString();
        myTAMoreDetail.PlanName = myDataTable.Rows[0]["PlanName"].ToString();
        myTAMoreDetail.PlanType = myDataTable.Rows[0]["PlanType"].ToString();
        myTAMoreDetail.CoverageLevel = myDataTable.Rows[0]["CoverageLevel"].ToString();
        myTAMoreDetail.Country = myDataTable.Rows[0]["Country"].ToString();
        myTAMoreDetail.Area = myDataTable.Rows[0]["Area"].ToString();
        myTAMoreDetail.Duration = myDataTable.Rows[0]["Duration"].ToString();
        myTAMoreDetail.StartDate = Convert.ToDateTime(myDataTable.Rows[0]["StartDate"].ToString());
        myTAMoreDetail.EndDate = Convert.ToDateTime(myDataTable.Rows[0]["EndDate"].ToString());
        myTAMoreDetail.ChildAge = Convert.ToInt32(myDataTable.Rows[0]["ChildAge"].ToString());
        myTAMoreDetail.AdultAge = Convert.ToInt32(myDataTable.Rows[0]["AdultAge"].ToString());
        myTAMoreDetail.NoOfTraveller = Convert.ToInt32(myDataTable.Rows[0]["NoOfTraveller"].ToString());

        myTAMoreDetail.TotalPremium = Convert.ToSingle(myDataTable.Rows[0]["TotalPremium"].ToString());
        myTAMoreDetail.PamentType = myDataTable.Rows[0]["PamentType"].ToString();
        myTAMoreDetail.ViewedDetailId = Convert.ToInt64(myDataTable.Rows[0]["ViewedDetailId"].ToString());
        myTAMoreDetail.RowGUID = myDataTable.Rows[0]["RowGUID"].ToString();
        myTAMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
        myTAMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());

        if (myDataTable.Rows[0]["Info1"].ToString() != "")
            myTAMoreDetail.Info1 = myDataTable.Rows[0]["Info1"].ToString();
        else
            myTAMoreDetail.Info1 = "0";

        if (myDataTable.Rows[0]["Info2"].ToString() != "")
            myTAMoreDetail.Info2 = myDataTable.Rows[0]["Info2"].ToString();
        else
            myTAMoreDetail.Info2 = "0";


        return myTAMoreDetail;
    }
}
